const Joi = require('Joi');
const GROUP_NAME = "shops";
// 引入 models
const models = require("../models");
const { paginationDefine } = require('../utils/router-helper');

module.exports = [
  {
    method: 'GET',
    path: '/shops',
    handler: async (request, h) => {
      // 通过 await 来异步查取数据
      const { rows: results, count: totalCount } = await models.shops.findAndCountAll (
        {
          attributes: [
            'id',
            'name',
          ],
          limit: request.query.limit,
          offset: (request.query.page - 1) * request.query.limit,
        }
      );
      return results;
    },
    config: {
      tags: ['api', GROUP_NAME],
      description: '获取店铺列表',
      validate: {
        // query: {
        //   ...paginationDefine
        // }
      }
    }
  }
]